package network.dataFormats;
import network.byteConversions.ByteConverter;
public class PackageHeader {
	public PackageType type;
	public int id;
	public float time;
	public PackageHeader(PackageType type, int id, float time) {
		this.type = type;
		this.id = id;
		this.time = time;
	}
	public PackageHeader(byte[] bytes) {
		int typeInt = ByteConverter.bytesToInt(bytes, 0);
		id = ByteConverter.bytesToInt(bytes, 4);
		time = ByteConverter.bytesToFloat(bytes, 8);
		type = PackageType.values()[typeInt];
	}
	public byte[] toBytes() {
		int typeInt = type.ordinal();
		byte[] bytes = new byte[12];
		ByteConverter.intToFourBytes(typeInt, bytes, 0);
		ByteConverter.intToFourBytes(id, bytes, 4);
		ByteConverter.floatToFourBytes(time, bytes, 8);
		return bytes;
	}
}
